/******************************************************************************

@File           : Sonant.h
@Author         : Sonant Synth by Jake Taylor
                : Windows Port by David Moloney, moloned@gmail.com
				; Realtime Sonant Synth by Conor Mac Aoidh, conormacaoidh@gmail.com
@Brief			: Realtime version of the Windows port of the Sonant Synth
Date            : 20/06/2012
Copyright       : (C) 2008-2009 Jake Taylor [ Ferris / Youth Uprising ]

******************************************************************************/

#ifndef _4K_SONANT_
#define _4K_SONANT_

/******************************************************************************
1: Definitions
******************************************************************************/

/*********************************************

	BUFF_SIZE

	Must be even number to enable
	stereo audio.

*********************************************/
#define BUFF_SIZE		0x23E2//0x166D4//	// buffer size
#define DEBUG							// uncomment to enable debug printfs

/******************************************************************************
2: Structure definitions
******************************************************************************/

typedef struct { // Columns
	unsigned char   n[32];          // Notes (pattern length is 32)
} column;

typedef struct { // Instrument
	// Oscillator 1
	unsigned char   osc1_oct;       // Octave knob
	unsigned char   osc1_det;       // Detune knob
	unsigned char   osc1_detune;    // Actual detune knob
	unsigned char   osc1_xenv;      // Multiply freq by envelope
	unsigned char   osc1_vol;       // Volume knob
	unsigned char   osc1_waveform;  // Wave form
	// Oscillator 2
	unsigned char   osc2_oct;       // Octave knob
	unsigned char   osc2_det;       // Detune knob
	unsigned char   osc2_detune;    // Actual detune knob
	unsigned char   osc2_xenv;      // Multiply freq by envelope
	unsigned char   osc2_vol;       // Volume knob
	unsigned char   osc2_waveform;  // Wave form
	// Noise oscillator
	unsigned char   noise_fader;    // Amount of noise to add
	// Envelope
	unsigned int    env_attack;     // Attack
	unsigned int    env_sustain;    // Sustain
	unsigned int    env_release;    // Release
	unsigned char   env_master;     // Master volume knob
	// Effects
	unsigned char   fx_filter;      // Hi/lo/bandpass or notch toggle
	float           fx_freq;        // FX Frequency
	unsigned char   fx_resonance;   // FX Resonance
	unsigned char   fx_delay_time;  // Delay time
	unsigned char   fx_delay_amt;   // Delay amount
	unsigned char   fx_pan_freq;    // Panning frequency
	unsigned char   fx_pan_amt;     // Panning amount
	// LFO
	unsigned char   lfo_osc1_freq;  // Modify osc1 freq (FM) toggle
	unsigned char   lfo_fx_freq;    // Modify fx freq toggle
	unsigned char   lfo_freq;       // LFO freq
	unsigned char   lfo_amt;        // LFO amount
	unsigned char   lfo_waveform;   // LFO waveform
	// Patterns
	char            p[48];          // Pattern order (Maximum 32 patterns)
	// Columns
	column          c[10];          // Columns (10 maximum)
} inst;

typedef struct{ // Songs
	inst i[8];	// Instruments (8 maximum)
} song;

typedef struct{ // buffer data
	unsigned int i_n;
	float c1;
	float c2;
	float low;
	float band;
} buff_data;

/******************************************************************************
3: Function prototypes
******************************************************************************/

float Sonant_randfloat4k();
int Sonant_clip(int value);
void Sonant_print_buffer( int i );
float Sonant_osc_sin(float value);
float Sonant_osc_square(float value);
float Sonant_osc_saw(float value);
float Sonant_osc_tri(float value);
float Sonant_getFrequency(float fFrequency, float fMultiplier, unsigned char nValue, unsigned char nLimit);
float Sonant_getnotefreq(unsigned char n);
float Sonant_getoscoutput(unsigned char nWaveform,float fValue);
int Sonant_render( short *left_buffer, short *right_buffer );
void Sonant_init( );
void Sonant_merge( short *wave_buffer, short *left_buffer, short *right_buffer );
void Sonant_generate_sample( unsigned int i_n, float *left, float *right );

#endif // _4K_SONANT_

/******************************************************************************
End of file
******************************************************************************/
